import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
// https://leetcode.cn/problems/non-decreasing-subsequences/
public class FindSubSequence {
    class Solution {
        private List<List<Integer>> res = new ArrayList<>();
        public List<List<Integer>> findSubsequences(int[] nums) {
            backTacking(new ArrayList<>(), 0 , nums);
            return res;



        }

        private void backTacking(List<Integer> path , int start , int[] nums)
        {
            if(path.size() >= 2)
            {
                res.add(new ArrayList<>(path));
            }


            HashSet<Integer> set = new HashSet<>();
            int tail = -120;
            if(path.size() != 0)
            {
                tail = path.get(path.size()-1);
            }
            for(int i = start ; i < nums.length ; i ++)
            {


                if(nums[i] >= tail  && !set.contains(nums[i]))
                {
                    set.add(nums[i]);
                    path.add(nums[i]);
                    backTacking(path,i + 1, nums);
                    path.remove(path.size()-1);
                }
            }
        }
    }
}
